package com.x.Part3_copyingAndAssignment;

/**
 * ClassName: Copying
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2023/9/14 2:57
 */
public class Copying {
    public static void main(String[] args) {
        int[] arr1, arr2;
        arr1 = new int[]{2,3,5,7,11,13,17,19};

        //复制arr1,放进arr2
        arr2 = new int[arr1.length];
        for (int i = 0; i < arr1.length; i++)
            arr2[i] = arr1[i];

        //查看arr2元素值
        for (int i = 0; i < arr2.length; i++)
            System.out.print(arr2[i]+"\t");

        System.out.println();

        //查看两个数组的地址,可发现地址不一致
        System.out.println(arr1);
        System.out.println(arr2);

        //改变arr2的元素值
        for(int i = 0; i < arr2.length; i++){
            if(i % 2 == 0)
                arr2[i] = i;
        }

        //发现arr1的值没有改变
        for (int i = 0; i < arr1.length; i++)
            System.out.print(arr1[i]+"\t");
    }
}
